<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE topic
  PUBLIC "-//OASIS//DTD DITA Composite//EN" "ditabase.dtd">
<topic id="topic1" xml:lang="en">
  <title id="hv156255">pg_statistic</title>
  <body>
    <p>The <codeph>pg_statistic</codeph> system catalog table stores statistical data about the
      contents of the database. Entries are created by <codeph>ANALYZE</codeph> and subsequently
      used by the query optimizer. There is one entry for each table column that has been analyzed.
      Note that all the statistical data is inherently approximate, even assuming that it is
      up-to-date.</p>
    <p><codeph>pg_statistic</codeph> also stores statistical data about the values of index
      expressions. These are described as if they were actual data columns; in particular,
        <codeph>starelid</codeph> references the index. No entry is made for an ordinary
      non-expression index column, however, since it would be redundant with the entry for the
      underlying table column. Currently, entries for index expressions always have
      <codeph>stainherit = false</codeph>.</p>
    <p>When <codeph>stainherit = false</codeph>, there is normally one entry for each table column
      that has been analyzed. If the table has inheritance children, Greenplum Database creates
      a second entry with <codeph>stainherit = true</codeph>. This row represents the column's
       statistics over the inheritance tree, for example, statistics for the data you would see
        with <codeph>SELECT <varname>column</varname> FROM <varname>table</varname>*</codeph>,
        whereas the <codeph>stainherit = false</codeph> row represents the results of
        <codeph>SELECT <varname>column</varname> FROM ONLY <varname>table</varname></codeph>.</p>
    <p>Since different kinds of statistics may be appropriate for different kinds of data,
        <codeph>pg_statistic</codeph> is designed not to assume very much about what sort of
      statistics it stores. Only extremely general statistics (such as nullness) are given dedicated
      columns in <codeph>pg_statistic</codeph>. Everything else is stored in slots, which are groups
      of associated columns whose content is identified by a code number in one of the slot's
      columns.</p>
    <p>Statistical information about a table's contents should be considered sensitive (for example:
      minimum and maximum values of a salary column). <codeph>pg_stats</codeph> is a publicly
      readable view on <codeph>pg_statistic</codeph> that only exposes information about those
      tables that are readable by the current user.</p>
    <note type="warning">Diagnostic tools such as <codeph>gpsd</codeph> and
        <codeph>minirepro</codeph> collect sensitive information from <codeph>pg_statistic</codeph>,
      such as histogram boundaries, in a clear, readable form. Always review the output files of
      these utilities to ensure that the contents are acceptable for transport outside of the
      database in your organization.</note>
    <table id="hv156260">
      <title>pg_catalog.pg_statistic</title>
      <tgroup cols="4">
        <colspec colnum="1" colname="col1" colwidth="131pt"/>
        <colspec colnum="2" colname="col2" colwidth="60.75pt"/>
        <colspec colnum="3" colname="col3" colwidth="104.25pt"/>
        <colspec colnum="4" colname="col4" colwidth="147pt"/>
        <thead>
          <row>
            <entry colname="col1">column</entry>
            <entry colname="col2">type</entry>
            <entry colname="col3">references</entry>
            <entry colname="col4">description</entry>
          </row>
        </thead>
        <tbody>
          <row>
            <entry colname="col1">
              <codeph>starelid</codeph>
            </entry>
            <entry colname="col2">oid</entry>
            <entry colname="col3">pg_class.oid </entry>
            <entry colname="col4">The table or index that the described column belongs to.</entry>
          </row>
          <row>
            <entry colname="col1">
              <codeph>staattnum</codeph>
            </entry>
            <entry colname="col2">int2</entry>
            <entry colname="col3">pg_attribute.attnum</entry>
            <entry colname="col4">The number of the described column.</entry>
          </row>
          <row>
            <entry colname="col1">
              <codeph>stainherit</codeph>
            </entry>
            <entry colname="col2">bool</entry>
            <entry colname="col3"/>
            <entry colname="col4">If true, the statistics include inheritance child columns,
              not just the values in the specified relations.</entry>
          </row>
          <row>
            <entry colname="col1">
              <codeph>stanullfrac</codeph>
            </entry>
            <entry colname="col2">float4</entry>
            <entry colname="col3"/>
            <entry colname="col4">The fraction of the column's entries that are null.</entry>
          </row>
          <row>
            <entry colname="col1">
              <codeph>stawidth</codeph>
            </entry>
            <entry colname="col2">int4</entry>
            <entry colname="col3"/>
            <entry colname="col4">The average stored width, in bytes, of nonnull entries.</entry>
          </row>
          <row>
            <entry colname="col1">
              <codeph>stadistinct</codeph>
            </entry>
            <entry colname="col2">float4</entry>
            <entry colname="col3"/>
            <entry colname="col4">The number of distinct nonnull data values in the column. A value
              greater than zero is the actual number of distinct values. A value less than zero is
              the negative of a fraction of the number of rows in the table (for example, a column
              in which values appear about twice on the average could be represented by
                <codeph>stadistinct</codeph> = -0.5). A zero value means the number of distinct
              values is unknown.</entry>
          </row>
          <row>
            <entry colname="col1">
              <codeph>stakind<i>N</i></codeph>
            </entry>
            <entry colname="col2">int2</entry>
            <entry colname="col3"/>
            <entry colname="col4">A code number indicating the kind of statistics stored in the
                <codeph>N</codeph>th slot of the <codeph>pg_statistic</codeph> row.</entry>
          </row>
          <row>
            <entry colname="col1">
              <codeph>staop<i>N</i></codeph>
            </entry>
            <entry colname="col2">oid</entry>
            <entry colname="col3">pg_operator.oid</entry>
            <entry colname="col4">An operator used to derive the statistics stored in the
                <codeph>N</codeph>th slot. For example, a histogram slot would show the
                <codeph>&lt;</codeph> operator that defines the sort order of the data.</entry>
          </row>
          <row>
            <entry colname="col1">
              <codeph>stanumbers<i>N</i></codeph>
            </entry>
            <entry colname="col2">float4[]</entry>
            <entry colname="col3"/>
            <entry colname="col4">Numerical statistics of the appropriate kind for the
                <codeph>N</codeph>th slot, or NULL if the slot kind does not involve numerical
              values.</entry>
          </row>
          <row>
            <entry colname="col1">
              <codeph>stavalues<i>N</i></codeph>
            </entry>
            <entry colname="col2">anyarray</entry>
            <entry colname="col3"/>
            <entry colname="col4">Column data values of the appropriate kind for the
                <codeph>N</codeph>th slot, or NULL if the slot kind does not store any data values.
              Each array's element values are actually of the specific column's data type, so there
              is no way to define these columns' type more specifically than
                <codeph>anyarray</codeph>.</entry>
          </row>
        </tbody>
      </tgroup>
    </table>
  </body>
</topic>
